<?php

namespace App\Admin\Controllers;

use App\Http\Controllers\Controller;
use App\Models\ChallengeGame;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class ChallengeGameController extends Controller
{
    use HasResourceActions;
    private $name = '挑战赛';

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header($this->name)
            ->description(trans('admin.list'))
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header($this->name)
            ->description(trans('admin.detail'))
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header($this->name)
            ->description(trans('admin.edit'))
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header($this->name)
            ->description(trans('admin.create'))
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new ChallengeGame);

        $grid->id('Id');
        $grid->play_a('挑战者(A)');
        $grid->play_b('应战者(B)');
        $grid->type('类型');
        $grid->game_datetime('比赛时间');
        $grid->address('地点');
        $grid->desc('补充说明');
        $grid->score_a('A得分');
        $grid->score_b('B得分');
        $grid->status('状态');

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(ChallengeGame::findOrFail($id));

        $show->id('Id');
        $show->play_a('Play a');
        $show->play_b('Play b');
        $show->type('Type');
        $show->game_datetime('Game datetime');
        $show->address('Address');
        $show->desc('Desc');
        $show->score_a('Score a');
        $show->score_b('Score b');
        $show->status('Status');
        $show->created_at('Created at');
        $show->updated_at('Updated at');

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new ChallengeGame);

        $form->number('play_a', 'Play a');
        $form->number('play_b', 'Play b');
        $form->number('type', 'Type')->default(1);
        $form->datetime('game_datetime', 'Game datetime')->default(date('Y-m-d H:i:s'));
        $form->text('address', 'Address');
        $form->text('desc', 'Desc');
        $form->number('score_a', 'Score a');
        $form->number('score_b', 'Score b');
        $form->number('status', 'Status')->default(10);

        return $form;
    }
}
